import { _decorator, Component, easing, Node, Sprite, tween, Tween, Vec3 } from 'cc';
import { GAME_TOP, GlobalData } from '../../../Data/GlobalData';
const { ccclass, property } = _decorator;

@ccclass('SingleBrick')
/**
 * 单根筷子
 */
export class SingleBrick extends Component {

    //筷子
    @property(Sprite)
    private Stick: Sprite = null;

    //索引
    public StickIndex: number = -1;

    //是否被选择了
    public IsChoose: boolean = false;

    /**
     * 更新筷子
     */
    public UpdateStick(_stickindex: number) {
        this.node.setScale(new Vec3(1, 1, 1));
        this.IsChoose = false;
        this.StickIndex = _stickindex;
        this.Stick.spriteFrame = app.resManager.SpriteFrames[GlobalData.Stick_Sprite + this.StickIndex]
    }

    /**
     * 播放出现动画
     */
    public PlayAppearAnimation(_pos: Vec3, _delay: number, _istouch: boolean) {
        Tween.stopAllByTarget(this.Stick.node);
        this.Stick.node.setWorldPosition(_pos);
        tween(this.Stick.node).delay(_delay * 0.1).to(0.3, { position: new Vec3(0, 0, 0) }, { easing: 'backOut' }).call(() => {
            if (_istouch) {
                console.log("可以点击")
                app.topManager.HideTop(GAME_TOP.NOTOUCH);
            }
        }).start();
    }

    /**
     * 播放错误动画
     */
    public PlayErrorAni() {
        console.log("播放错误动画")
        tween(this.Stick.node)
            .to(0.05, { angle: -15 }).to(0.05, { angle: 0 })
            .to(0.05, { angle: 15 }).to(0.05, { angle: 0 })
            .start();
    }

}


